/**
 * Created by charsen on 16/5/26.
 */
directives.directive('flyField', ["$rootScope", "tools", "$timeout", function ($rootScope, tools, $timeout) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attr) {
            $rootScope.$on('FLY_EV', function (e, begin, end, type, columnDesc) {
                $('#fly-field').css({
                    left: begin.left,
                    top: begin.top
                });
                var bool = new Parabola({
                    el: "#fly-field",
                    offset: [end.left - begin.left, end.top - begin.top],
                    curvature: 0.003,
                    duration: 500,
                    callback: function () {
                        $('#fly-field').css({
                            left: '-30px',
                            top: '-30px'
                        });
                        $rootScope.$broadcast('FIELD_EV', type, columnDesc,'add');
                    },
                    stepCallback: function (x, y) {
                    }
                });
                bool.start();
            });
        },
        templateUrl: "/trend-new-BI/app/components/editor/flyField/flyFieldView.html"
    }
}]);